package com.ruoyi.project.system.house.img.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.house.img.domain.HouseImg;
import com.ruoyi.project.system.house.img.service.IHouseImgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 房源图片Controller
 * 
 * @author f_baisi
 * @date 2020-08-27
 */
@Controller
@RequestMapping("/system/house/img")
public class HouseImgController extends BaseController
{
    private String prefix = "system/house/img";

    @Autowired
    private IHouseImgService houseImgService;

    @RequiresPermissions("system/house:img:view")
    @GetMapping()
    public String img()
    {
        return prefix + "/img";
    }

    /**
     * 查询房源图片列表
     */
    @RequiresPermissions("system/house:img:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouseImg houseImg)
    {
        startPage();
        List<HouseImg> list = houseImgService.selectHouseImgList(houseImg);
        return getDataTable(list);
    }

    /**
     * 导出房源图片列表
     */
    @RequiresPermissions("system/house:img:export")
    @Log(title = "房源图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouseImg houseImg)
    {
        List<HouseImg> list = houseImgService.selectHouseImgList(houseImg);
        ExcelUtil<HouseImg> util = new ExcelUtil<HouseImg>(HouseImg.class);
        return util.exportExcel(list, "img");
    }

    /**
     * 新增房源图片
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房源图片
     */
    @RequiresPermissions("system/house:img:add")
    @Log(title = "房源图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouseImg houseImg)
    {
        return toAjax(houseImgService.insertHouseImg(houseImg));
    }

    /**
     * 修改房源图片
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        HouseImg houseImg = houseImgService.selectHouseImgById(id);
        mmap.put("houseImg", houseImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存房源图片
     */
    @RequiresPermissions("system/house:img:edit")
    @Log(title = "房源图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouseImg houseImg)
    {
        return toAjax(houseImgService.updateHouseImg(houseImg));
    }

    /**
     * 删除房源图片
     */
    @RequiresPermissions("system/house:img:remove")
    @Log(title = "房源图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houseImgService.deleteHouseImgByIds(ids));
    }
}
